package polimi.disttest.manager;
import com.jcraft.jsch.Logger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class JSchCommonsLogger implements Logger{
	private Log log;
	
	/**
     * Constructor with custom category name 
     * 
     * @param logName the category name used by this logger for Apache Commons.
     */
    public JSchCommonsLogger(String logName) {
        log = LogFactory.getLog(logName);
    }
    
    /**
     * Default constructor
     */
    public JSchCommonsLogger() {
        this(Logger.class.getName());
    }

    /* (non-Javadoc)
     * @see com.jcraft.jsch.Logger#isEnabled(int)
     */
    public boolean isEnabled(int level) {
        switch (level) {
        case DEBUG:
            return log.isDebugEnabled();
        case INFO:
            return log.isInfoEnabled();
        case WARN:
            return log.isWarnEnabled();
        case ERROR:
            return log.isErrorEnabled();
        case FATAL:
            return log.isFatalEnabled();
        }
        return false;
    }

    /* (non-Javadoc)
     * @see com.jcraft.jsch.Logger#log(int, java.lang.String)
     */
    public void log(int level, String message) {
        switch (level) {
        case DEBUG:
            log.debug(message);
            break;
        case INFO:
            log.info(message);
            break;
        case WARN:
            log.warn(message);
            break;
        case ERROR:
            log.error(message);
            break;
        case FATAL:
            log.fatal(message);
            break;
        }
    }
}
